import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:luckin_demo/drawerdemo/button/my_button.dart';
import 'package:luckin_demo/drawerdemo/page/models/food.dart';
import 'package:luckin_demo/drawerdemo/theme/colors.dart';

import 'food_detials.dart';
import 'food_tile.dart';

class MenuPage extends StatefulWidget {
  const MenuPage({super.key});

  @override
  State<MenuPage> createState() => _MenuPageState();
}

class _MenuPageState extends State<MenuPage> {

  List foodMenu = [
    //salmon sushi
    Food('Salmon Sushi', '21.00', 'lib/assets/sushi/uramaki.png', '4.9'),
    Food('Tuna', '33.00', 'lib/assets/sushi/sushi.png', '4.3'),

  ];

  void navigateToFoodDetials(int index){

     Get.to(FoodDetialsPage(food: foodMenu[index],),);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[300],
      drawer:  Drawer(
        backgroundColor: Color(0xFF2d3447),
        child: Column(
          children: [
            Row(
              children: [
                Expanded(
                    flex: 1,
                    child:
                    UserAccountsDrawerHeader(
                      accountName: const Text("COjiji"),
                      accountEmail: const Text("99088454@qq.com"),
                      decoration: const BoxDecoration(
                        image: DecorationImage(
                            fit: BoxFit.fill,
                            image: NetworkImage(
                              "https://www.itying.com/images/flutter/3.png",
                            )),
                      ),
                      currentAccountPicture: const CircleAvatar(
                        backgroundImage: NetworkImage(
                            "https://www.itying.com/images/flutter/5.png"),
                      ),
                      otherAccountsPictures: [
                        Image.network("https://www.itying.com/images/flutter/1.png"),
                        Image.network("https://www.itying.com/images/flutter/2.png"),
                        Image.network("https://www.itying.com/images/flutter/4.png"),
                      ],
                    ))
              ],
            ),
            const SizedBox(
              height: 20,
            ),
            const ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.people),
              ),
              title: Text("个人中心",style: TextStyle(color: Colors.cyan),),
            ),
            const Divider(color: Colors.grey,indent:20,endIndent: 50,),
            const ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.offline_bolt),
              ),
              title: Text("系统设置",style: TextStyle(color: Colors.cyan),),
            ),
            const Divider(color: Colors.grey,indent:20,endIndent: 50,),
            const ListTile(
              leading: CircleAvatar(
                child: Icon(Icons.offline_bolt),
              ),
              title: Text("系统设置",style: TextStyle(color: Colors.cyan),),
            ),
          ],
        ),
      ),
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
        leading:Builder(builder: (BuildContext context) {
          return IconButton(
            padding: EdgeInsets.only(left: 18.0),
            icon: const Icon( Icons.menu,size: 30,),
            onPressed: (){
              Scaffold.of(context).openDrawer();
            },
          );
        }),



        title: Text('Tokyo',style: TextStyle(color: Colors.grey[900]),),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            decoration: BoxDecoration(color: primaryColor,borderRadius: BorderRadius.circular(25)),
            padding: EdgeInsets.symmetric(vertical: 25,horizontal: 40),
            margin: EdgeInsets.symmetric(horizontal: 25),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Column(
                  children: [
                    Text('Get 32% Promo'),
                    SizedBox(height: 20,),
                    MyButton(text: 'Redeem',onTop: (){},)
                  ],
                ),
                Image.asset('lib/assets/sushi/sushi2.png',height: 100,)
              ],
            ),
          ),
          SizedBox(height: 25,),
          Padding(padding: EdgeInsets.symmetric(horizontal: 25),
            child: TextField(
              decoration: InputDecoration(
                focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(color: Colors.white),
                    borderRadius: BorderRadius.circular(20)
                ),
                enabledBorder: OutlineInputBorder(
                    borderSide: BorderSide(color: Colors.white),
                    borderRadius: BorderRadius.circular(20)
                ),
                hintText: 'Search here ...'
              ),

            ),
          ),
          SizedBox(height: 25,),
          Padding(padding: EdgeInsets.symmetric(horizontal: 25),
            child: Text('Food Menu',style: TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.grey[800],
                fontSize: 18
            ),),
          ),
          Expanded(child: Padding(
            padding: EdgeInsets.only(left: 25),
            child: ListView.builder(itemBuilder: (context,index)=>FoodTile(food: foodMenu[index],onTop:() =>navigateToFoodDetials(index),),
              itemCount: foodMenu.length,
              scrollDirection: Axis.horizontal,
            ),
          )),
          SizedBox(height: 25,),
          Container(
            decoration: BoxDecoration(
              color: Colors.grey[100],
              borderRadius: BorderRadius.circular(20)
            ),
            margin: EdgeInsets.only(left: 25,right: 25,bottom: 25),
            padding: EdgeInsets.all(20),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    Image.asset('lib/assets/sushi/sushi2.png',height: 60,),
                    const SizedBox(width: 20,),
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text('Salmon Eggs',),
                        SizedBox(height: 10,),
                        Text('\$ 21.00',style: TextStyle(color: Colors.grey[700]),)
                      ],
                    ),
                  ],
                ),
                Icon(Icons.favorite_outlined,color: Colors.red,),
              ],
            ),
          )

        ],
      ),
    );
  }
}
